//请求用
var parselist_request = {};
//编辑用
var editmodel = [];
//表格用
var tablelist = [];
//更新
$.ajax({
	url: 'http://' + ipm + ':8081/dict/query',
	type: 'POST',
	contentType: 'application/json',
	dataType: 'json',
	data: {},
	success: function (response) {
		console.log(response);
		protolistRead(response);
	}
});

function refreshTab() {
	$.ajax({
		url: 'http://' + ipm + ':8081/dict/query',
		type: 'POST',
		contentType: 'application/json',
		dataType: 'json',
		data: {},
		success: function (response) {
			console.log(response);
			tablelist = [];
			protolistRead(response);
		}
	});
}



function createTab() {
	$("#table_page").bootstrapTable('destroy');
	$("#table_page").bootstrapTable({
		//url: '',
		data: tablelist,
		dataType: 'json',
		//method: 'POST',                      //请求方式（*）
		//toolbar: '#toolbar',              //工具按钮用哪个容器
		striped: true,                      //是否显示行间隔色
		cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
		pagination: true,                   //是否显示分页（*）
		sortable: true,                     //是否启用排序
		sortOrder: "asc",                   //排序方式
		sidePagination: "client",           //分页方式：client客户端分页，server服务端分页（*）
		pageNumber: 1,                      //初始化加载第一页，默认第一页,并记录
		pageSize: 10,                     //每页的记录行数（*）
		pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
		search: false,                      //是否显示表格搜索
		strictSearch: true,
		//showColumns: true,                  //是否显示所有的列（选择显示的列）
		//showRefresh: true,                  //是否显示刷新按钮
		minimumCountColumns: 1,             //最少允许的列数
		clickToSelect: true,                //是否启用点击选中行
		//height: 500,                      //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
		uniqueId: "name",                     //每一行的唯一标识，一般为主键列
		//showToggle: true,                   //是否显示详细视图和列表视图的切换按钮
		cardView: false,                    //是否显示详细视图
		detailView: false,                  //是否显示父子表
		//得到查询的参数
		queryParams: function (params) {
			//这里的键的名字和控制器的变量名必须一致，这边改动，控制器也需要改成一样的
			var temp = {
				rows: params.limit,                         //页面大小
				page: (params.offset / params.limit) + 1,   //页码
				sort: params.sort,      //排序列名  
				sortOrder: params.order //排位命令（desc，asc） 
			};
			return temp;
		},

		columns: [{
			field: 'name',
			title: '协议解析表名'
		}, {
			field: 'inserttime',
			title: '插入时间'
		}, {
			field: 'updatetime',
			title: '更新时间'
		}, {
			field: 'ID',
			title: '编辑',
			width: 120,
			align: 'center',
			valign: 'middle',
			formatter: actionFormatter
		}, {
			field: 'name',
			title: '删除',
			width: 120,
			align: 'center',
			valign: 'middle',
			formatter: actionFormatterD
		},
		],
		onLoadSuccess: function () {
		},
		onLoadError: function () {
			showTips("数据加载失败！");
		},
		onDblClickRow: function (row, $element) {
			var id = row.ID;
			EditViewById(id, 'view');
		},

	});

}

function actionFormatter(value, row, index) {
	var id = value;
	var result = "";
	result += "<a href='javascript:;' class='btn btn-xs blue' onclick=\"parselistEditViewById('" + id + "')\" title='编辑'><span class='feather-edit'></span></a>";

	return result;
}
function actionFormatterD(value, row, index) {
	var id = value;

	var result = "";
	result += "<a href='javascript:;' class='btn btn-xs red' onclick=\"parselist_modify('" + id + "')\" title='删除'><span class='feather-trash-2'></span></a>";

	return result;
}

// //新增模态框清理
// $('#parselistModal').on('hidden.bs.modal', function () {
// 	deletedictViewAdd();
// });

function deletedictViewAdd() {
	var Table = document.getElementById("tableroom");

	let tbody = Table.tBodies[0];

	// 循环删除 tbody 的所有行
	while (tbody.rows.length > 0) {
		tbody.deleteRow(0);
	}

}

//模态框清理
$('#myModal').on('hidden.bs.modal', function () {
	deleteparselistViewEdit();
});

function deleteparselistViewEdit() {
	var Table = document.getElementById("parselistView");
	var rows = Table.getElementsByTagName("tr").length;
	var rowsNum = 0;
	for (rowsNum; rowsNum < rows - 1; rowsNum++) {
		NewRow = Table.deleteRow(-1); //添加
	}
}

//新增字典模态框构建
function createParselistModel() {
	$('#parselistModal').modal('show');

}





var parselistnameroom
//编辑协议字段解析表
function parselistEditViewById(args) {
	$('#myModal').modal('show');
	var Table = document.getElementById("parselistView");
	currentId = args - 1;
	console.log(parselist_request);
	var parselistA = parselist_request.parse_list;
	parselistnameroom = parselistA[args - 1].name;
	console.log(parselistnameroom);
	var rowsNum = 0;
	var parselist
	//判断编辑字段下拉框已选中
	var selectOption
	var empty_logical_expressions
	var empty_unit
	for (var i = 0; i < parselistA.length; i++) {
		parselist = parselistA[i].context
		if (parselistA[i].name == parselistnameroom) {
			for (var j = 0; j < parselist.length; j++) {
				if (parselist[j].value_type == "char") {
					selectOption = '<select id = value_type' + (rowsNum + 1) + ' Name=value_type' + (rowsNum + 1) + ' class="form-contro form-control-sm" type="text"><option selected id = "char" name = "char" value="char">char</option><option value="short">short</option><option value="int">int</option><option value="double">double</option><option value="float">float</option><option value="long">long</option><option value="unsigned char">unsigned char</option><option value="unsigned short">unsigned short</option><option value="unsigned int">unsigned int</option><option value="unsigned long">unsigned long</option></select>';
				}
				else if (parselist[j].value_type == "short") {
					selectOption = '<select id = value_type' + (rowsNum + 1) + ' Name=value_type' + (rowsNum + 1) + ' class="form-contro form-control-sm" type="text"><option value="char">char</option><option selected value="short">short</option><option value="int">int</option><option value="double">double</option><option value="float">float</option><option value="long">long</option><option value="unsigned char">unsigned char</option><option value="unsigned short">unsigned short</option><option value="unsigned int">unsigned int</option><option value="unsigned long">unsigned long</option></select>';
				}
				else if (parselist[j].value_type == "int") {
					selectOption = '<select id = value_type' + (rowsNum + 1) + ' Name=value_type' + (rowsNum + 1) + ' class="form-contro form-control-sm" type="text"><option value="char">char</option><option value="short">short</option><option selected value="int">int</option><option value="double">double</option><option value="float">float</option><option value="long">long</option><option value="unsigned char">unsigned char</option><option value="unsigned short">unsigned short</option><option value="unsigned int">unsigned int</option><option value="unsigned long">unsigned long</option></select>';
				}
				else if (parselist[j].value_type == "double") {
					selectOption = '<select id = value_type' + (rowsNum + 1) + ' Name=value_type' + (rowsNum + 1) + ' class="form-contro form-control-sm" type="text"><option value="char">char</option><option value="short">short</option><option value="int">int</option><option selected value="double">double</option><option value="float">float</option><option value="long">long</option><option value="unsigned char">unsigned char</option><option value="unsigned short">unsigned short</option><option value="unsigned int">unsigned int</option><option value="unsigned long">unsigned long</option></select>';
				}
				else if (parselist[j].value_type == "float") {
					selectOption = '<select id = value_type' + (rowsNum + 1) + ' Name=value_type' + (rowsNum + 1) + ' class="form-contro form-control-sm" type="text"><option value="char">char</option><option value="short">short</option><option value="int">int</option><option value="double">double</option><option selected value="float">float</option><option value="long">long</option><option value="unsigned char">unsigned char</option><option value="unsigned short">unsigned short</option><option value="unsigned int">unsigned int</option><option value="unsigned long">unsigned long</option></select>';
				}
				else if (parselist[j].value_type == "long") {
					selectOption = '<select id = value_type' + (rowsNum + 1) + ' Name=value_type' + (rowsNum + 1) + ' class="form-contro form-control-sm" type="text"><option value="char">char</option><option value="short">short</option><option value="int">int</option><option value="double">double</option><option value="float">float</option><option selected value="long">long</option><option value="unsigned char">unsigned char</option><option value="unsigned short">unsigned short</option><option value="unsigned int">unsigned int</option><option value="unsigned long">unsigned long</option></select>';
				}
				else if (parselist[j].value_type == "unsigned char") {
					selectOption = '<select id = value_type' + (rowsNum + 1) + ' Name=value_type' + (rowsNum + 1) + ' class="form-contro form-control-sm" type="text"><option value="char">char</option><option value="short">short</option><option value="int">int</option><option value="double">double</option><option value="float">float</option><option value="long">long</option><option selected value="unsigned char">unsigned char</option><option value="unsigned short">unsigned short</option><option value="unsigned int">unsigned int</option><option value="unsigned long">unsigned long</option></select>';
				}
				else if (parselist[j].value_type == "unsigned short") {
					selectOption = '<select id = value_type' + (rowsNum + 1) + ' Name=value_type' + (rowsNum + 1) + ' class="form-contro form-control-sm" type="text"><option value="char">char</option><option value="short">short</option><option value="int">int</option><option value="double">double</option><option value="float">float</option><option value="long">long</option><option value="unsigned char">unsigned char</option><option selected value="unsigned short">unsigned short</option><option value="unsigned int">unsigned int</option><option value="unsigned long">unsigned long</option></select>';
				}
				else if (parselist[j].value_type == "unsigned int") {
					selectOption = '<select id = value_type' + (rowsNum + 1) + ' Name=value_type' + (rowsNum + 1) + ' class="form-contro form-control-sm" type="text"><option value="char">char</option><option value="short">short</option><option value="int">int</option><option value="double">double</option><option value="float">float</option><option value="long">long</option><option value="unsigned char">unsigned char</option><option value="unsigned short">unsigned short</option><option selected value="unsigned int">unsigned int</option><option value="unsigned long">unsigned long</option></select>';
				}
				else if (parselist[j].value_type == "unsigned long") {
					selectOption = '<select id = value_type' + (rowsNum + 1) + ' Name=value_type' + (rowsNum + 1) + ' class="form-contro form-control-sm" type="text"><option value="char">char</option><option value="short">short</option><option value="int">int</option><option value="double">double</option><option value="float">float</option><option value="long">long</option><option value="unsigned char">unsigned char</option><option value="unsigned short">unsigned short</option><option value="unsigned int">unsigned int</option><option selected value="unsigned long">unsigned long</option></select>';
				}
				// if (parselist[j].logical_expressions == "") {
				// 	empty_logical_expressions = "<input id = logical_expressions" + (rowsNum + 1) + " Name=logical_expressions" + (rowsNum + 1) + " placeholder='未定义' value='无' class='form-control form-control-sm' type='text' />";
				// } else {
				// 	empty_logical_expressions = "<input id = logical_expressions" + (rowsNum + 1) + " Name=logical_expressions" + (rowsNum + 1) + " placeholder='未定义' value=" + editmodel[args - 1][rowsNum].logical_expressions + " class='form-control form-control-sm' type='text' />";
				// }
			}

		}
	}

	for (rowsNum; rowsNum < editmodel[args - 1].length; rowsNum++) {
		NewRow = Table.insertRow(); //添加行
		//添加列
		Name = NewRow.insertCell();
		value_type = NewRow.insertCell();
		value_length = NewRow.insertCell();
		logical_expressions = NewRow.insertCell();
		dbfield = NewRow.insertCell();
		unit = NewRow.insertCell();
		operate = NewRow.insertCell();

		//属性赋值'<select id = value_type" + (rowsNum + 1)+" Name=value_type" +  (rowsNum + 1) +" class="form-contro form-control-sm" type="text"><option value="char">char</option><option value="short">short</option><option value="int">int</option><option value="double">double</option><option value="float">float</option><option value="long">long</option><option value="unsigned char">unsigned char</option><option value="unsigned short">unsigned short</option><option value="unsigned int">unsigned int</option><option value="unsigned long">unsigned long</option></select>';
		Name.innerHTML = "<input id = name" + (rowsNum + 1) + " Name=name" + (rowsNum + 1) + " value=" + editmodel[args - 1][rowsNum].name + " class='form-control form-control-sm' type='text' />";
		// value_type.innerHTML = "<input id = value_type" + (rowsNum + 1) + " Name=value_type" + (rowsNum + 1) + " value=" + editmodel[args - 1][rowsNum].value_type + " class='form-control form-control-sm' type='text' />";
		value_type.innerHTML = selectOption
		value_length.innerHTML = "<input id = value_length" + (rowsNum + 1) + " Name=value_length" + (rowsNum + 1) + "  value=" + editmodel[args - 1][rowsNum].value_length + " class='form-control form-control-sm' type='text' />";
		if (editmodel[args - 1][rowsNum].logical_expressions) {
			logical_expressions.innerHTML = "<input id = logical_expressions" + (rowsNum + 1) + " Name=logical_expressions" + (rowsNum + 1) + " placeholder='未定义' value=" + editmodel[args - 1][rowsNum].logical_expressions + " class='form-control form-control-sm' type='text' />";
		} else {
			logical_expressions.innerHTML = "<input id = logical_expressions" + (rowsNum + 1) + " Name=logical_expressions" + (rowsNum + 1) + " placeholder='未定义' value='' class='form-control form-control-sm' type='text' />";
		}
		if (editmodel[args - 1][rowsNum].dbfield) {
			dbfield.innerHTML = "<input id = dbfield" + (rowsNum + 1) + " Name=dbfield" + (rowsNum + 1) + " placeholder='未定义' value='" + editmodel[args - 1][rowsNum].dbfield + "' class='form-control form-control-sm' type='text' />";
		} else {
			dbfield.innerHTML = "<input id = dbfield" + (rowsNum + 1) + " Name=dbfield" + (rowsNum + 1) + " placeholder='未定义' value='' class='form-control form-control-sm' type='text' />";
		}
		// logical_expressions.innerHTML = empty_logical_expressions
		if (editmodel[args - 1][rowsNum].unit) {
			unit.innerHTML = "<input id = unit" + (rowsNum + 1) + " Name=unit" + (rowsNum + 1) + "  value=" + editmodel[args - 1][rowsNum].unit + " class='form-control form-control-sm' type='text' />";
		} else {
			unit.innerHTML = "<input id = unit" + (rowsNum + 1) + " Name=unit" + (rowsNum + 1) + " placeholder='未定义' value='' class='form-control form-control-sm' type='text' />";
		}
		operate.innerHTML = '<div id=operate' + (rowsNum + 1) + '><a style="cursor:pointer;color:#007bff;"  onclick="deleteInterfaceParselistParam(' + (args - 1) + ');">删除</a></div>';
		// operate.innerHTML = '<div id=operate' + (rowsNum + 1) + '><a href="javascript:;" class="btn btn-xs red" onclick="deleteInterfaceParselistParam(' + (args - 1) + ');" title="删除"><span class="feather-trash-2"></span></a></div>';
		//选中类型后长度框体输入限制
		// <a href="javascript:;" class="btn btn-xs red" onclick="deleteInterfaceParselistParam(' + (args - 1) + ');" title="删除"><span class="feather-trash-2"></span></a>
		// var selectEle = document.getElementById('value_type' + (rowsNum + 1));
		// var value_selected = selectEle.options[selectEle.selectedIndex].value;
		// if(value_selected == "char"){
		// 	$("#value_length" + (rowsNum + 1)).attr("disabled","disabled");
		// } else if (value_selected == "short") {
		// 	$("#value_length" + (rowsNum + 1)).attr("disabled","disabled");
		// } else if (value_selected == "int") {
		// 	$("#value_length" + (rowsNum + 1)).attr("disabled","disabled");
		// } else if (value_selected == "double") {
		// 	$("#value_length" + (rowsNum + 1)).attr("disabled","disabled");
		// } else if (value_selected == "float") {
		// 	$("#value_length" + (rowsNum + 1)).attr("disabled","disabled");
		// } else if (value_selected == "long") {
		// 	$("#value_length" + (rowsNum + 1)).attr("disabled","disabled");
		// } else if (value_selected == "unsigned char") {

		// } else if (value_selected == "unsigned char") {
		// 	$("#value_length" + (rowsNum + 1)).attr("disabled","disabled");
		// } else if (value_selected == "unsigned int") {
		// 	$("#value_length" + (rowsNum + 1)).attr("disabled","disabled");
		// } else if (value_selected == "unsigned long") {
		// 	$("#value_length" + (rowsNum + 1)).attr("disabled","disabled");
		// }

		// var select = document.getElementById('value_type' + (rowsNum + 1));
		// select.addEventListener('change', function () {
		// 	var selectedOption = select.options[select.selectedIndex];
		// 	if (selectedOption.value == "char") {
		// 		console.log(11111)
		// 		$("#value_length" + (rowsNum + 1)).attr("disabled","disabled");
		// 	} else if (selectedOption.value == "short") {
		// 		$("#value_length" + (rowsNum + 1)).prop('disabled', true);
		// 	} else if (selectedOption.value == "int") {
		// 		$("#value_length" + (rowsNum + 1)).prop('disabled', true);
		// 	} else if (selectedOption.value == "double") {
		// 		$("#value_length" + (rowsNum + 1)).prop('disabled', true);
		// 	} else if (selectedOption.value == "float") {
		// 		$("#value_length" + (rowsNum + 1)).prop('disabled', true);
		// 	} else if (selectedOption.value == "long") {
		// 		$("#value_length" + (rowsNum + 1)).prop('disabled', true);
		// 	} else if (selectedOption.value == "unsigned char") {
		// 		$("#value_length" + (rowsNum + 1)).prop('disabled', true);
		// 	} else if (selectedOption.value == "unsigned short") {
		// 		$("#value_length" + (rowsNum + 1)).prop('disabled', true);
		// 	} else if (selectedOption.value == "unsigned int") {
		// 		$("#value_length" + (rowsNum + 1)).prop('disabled', true);
		// 	} else if (selectedOption.value == "unsigned long") {
		// 		$("#value_length" + (rowsNum + 1)).prop('disabled', true);
		// 	}

		// 	console.log(selectedOption.value);
		// 	// 在这里添加需要执行的操作
		// });


	}


}

//ID编辑插入一行
function addparselistEditViewTable() {
	var Table = document.getElementById("parselistView");

	var rowsNum = Table.rows.length - 1;
	NewRow = Table.insertRow(); //添加行
	//添加列
	Name = NewRow.insertCell();
	value_type = NewRow.insertCell();
	value_length = NewRow.insertCell();
	logical_expressions = NewRow.insertCell();
	dbfield = NewRow.insertCell();
	unit = NewRow.insertCell();
	operate = NewRow.insertCell();

	//属性赋值

	Name.innerHTML = "<input id = name" + (rowsNum + 1) + " Name=name" + (rowsNum + 1) + " class='form-control form-control-sm'  type='text' />";
	// value_type.innerHTML = "<input id = value_type" + (rowsNum + 1) + " Name=value_type" + (rowsNum + 1) + " class='form-control form-control-sm'  type='text' />";
	value_type.innerHTML = '<select id = value_type" + (rowsNum + 1)+" Name=value_type" +  (rowsNum + 1) +" class="form-contro form-control-sm" type="text"><option value="char">char</option><option value="short">short</option><option value="int">int</option><option value="double">double</option><option value="float">float</option><option value="long">long</option><option value="unsigned char">unsigned char</option><option value="unsigned short">unsigned short</option><option value="unsigned int">unsigned int</option><option value="unsigned long">unsigned long</option></select>';
	value_length.innerHTML = "<input id = value_length" + (rowsNum + 1) + " Name=value_length" + (rowsNum + 1) + " class='form-control form-control-sm'  type='text' />";
	logical_expressions.innerHTML = "<input id = logical_expressions" + (rowsNum + 1) + " Name=logical_expressions" + (rowsNum + 1) + " class='form-control form-control-sm'  type='text' />";
	dbfield.innerHTML = "<input id = dbfield" + (rowsNum + 1) + " Name=dbfield" + (rowsNum + 1) + " class='form-control form-control-sm'  type='text' />";
	unit.innerHTML = "<input id = unit" + (rowsNum + 1) + " Name=unit" + (rowsNum + 1) + " class='form-control form-control-sm'  type='text' />";
	operate.innerHTML = '<div id=operate' + (rowsNum + 1) + '><a style="cursor:pointer;color:#007bff;"  onclick="deleteInterfaceParselistParam();">删除</a></div>';

}

//删除编辑中的字典字段
function deleteInterfaceParselistParam() {
	var td = event.srcElement; // 通过event.srcElement 获取激活事件的对象 td
	var key = td.parentElement.parentElement.parentNode.rowIndex;  //获取行索引
	document.getElementById("parselistView").deleteRow(key); //删除
}



//增加一个协议字段解析表
var tableN = 0;
function addParselistTable() {
	var Tableroom = document.getElementById("tableroom");
	var tableNum = Tableroom.rows.length - 1;
	NewRow = Tableroom.insertRow(); //添加行
	room = NewRow.insertCell();

	room.innerHTML = '<div class="row"><div class="col-12"><div class="card"><div class="card-body"><div class="form-group row mb-3"><label for=dict' + (tableNum + 1) + ' class="col-4 col-form-label">协议解析表名：</label><div class="col-8"><input type="text" class="form-control" id=list' + (tableNum + 1) + ' name=list' + (tableNum + 1) + ' value=list' + (tableNum + 1) + '></div></div><table class="table-1" id = parselist' + (tableNum + 1) + '><tr ><td align = "center" style="width: 160px;">名称</td><td align = "center" style="width: 120px;">值类型</td><td align = "center" style="width: 80px;" >值长度</td><td align = "center" style="width: 180px;">逻辑表达式</td><td align = "center" style="width: 180px;">数据库表字段名</td><td align = "center" style="width: 130px;">单位</td><td align = "center" style="width: 60px;">操作</td></tr></table><div><a href="javascript:;" onclick= "addParselist(' + (tableNum + 1) + ')" title="添加"><span  class="feather-plus-circle"></span></a></div></div></div></div>';
	tableN++;
}

//插入一行协议字段解析表字段
function addParselist(args) {
	var Table = document.getElementById("parselist" + args);

	var rowsNum = Table.rows.length - 1;
	NewRow = Table.insertRow(); //添加行
	//添加列
	Name = NewRow.insertCell();
	value_type = NewRow.insertCell();
	value_length = NewRow.insertCell();
	logical_expressions = NewRow.insertCell();
	dbfield = NewRow.insertCell();
	unit = NewRow.insertCell();
	operate = NewRow.insertCell();

	//属性赋值

	Name.innerHTML = "<input id = name" + (rowsNum + 1) + " Name=name" + (rowsNum + 1) + " class='form-control form-control-sm' type='text' />";
	value_type.innerHTML = '<select id = value_type" + (rowsNum + 1)+" Name=value_type" +  (rowsNum + 1) +" class="form-contro form-control-sm" type="text"><option value="char">char</option><option value="short">short</option><option value="int">int</option><option value="double">double</option><option value="float">float</option><option value="long">long</option><option value="unsigned char">unsigned char</option><option value="unsigned short">unsigned short</option><option value="unsigned int">unsigned int</option><option value="unsigned long">unsigned long</option></select>';
	value_length.innerHTML = "<input id = value_length" + (rowsNum + 1) + " Name=value_length" + (rowsNum + 1) + "  class='form-control form-control-sm' placeholder='非char可不填' />";
	logical_expressions.innerHTML = "<input id = logical_expressions" + (rowsNum + 1) + " Name=logical_expressions" + (rowsNum + 1) + " placeholder='未定义' class='form-control form-control-sm' type='text' />";
	dbfield.innerHTML = "<input id = dbfield" + (rowsNum + 1) + " Name=dbfield" + (rowsNum + 1) + " placeholder='未定义' class='form-control form-control-sm' type='text' />";
	unit.innerHTML = "<input id = unit" + (rowsNum + 1) + " Name=unit" + (rowsNum + 1) + "  class='form-control form-control-sm' type='text' />";
	operate.innerHTML = '<div id=operate' + (rowsNum + 1) + '><a style="cursor:pointer;color:#007bff;"  onclick="deleteParselist(' + args + ');">删除</a></div>';

}

//删除一行协议字段解析表字段
function deleteParselist(args) {
	var td = event.srcElement; // 通过event.srcElement 获取激活事件的对象 td
	var key = td.parentElement.parentElement.parentNode.rowIndex;  //获取行索引
	document.getElementById('parselist' + args).deleteRow(key); //删除
}



//检查是否有空
function checkParselist(args) {
	console.log(args);
	var j = 1;
	var k = 1;
	var l = 1;
	for (var i = 0; i < args.length; i++) {
		var Name = document.getElementById(args[i].name).value;
		if (Name.length == 0) {
			if (args[i].name == "logical_expressions" + j) {
				j++;
				i++;
				continue;
			} else if (args[i].name == "value_length" + k) {
				k++;
				i++;
				continue;
			} else if (args[i].name == "dbfield" + l) {
				l++;
				i++;
				continue;
			}
			alert('输入不能为空');
			return false;
		}
	}
}

//新增一个协议字段解析表
function buildParselistJson(args) {
	var register = $("#parselistForm");
	formData = register.serializeArray();
	if (checkParselist(formData) == false) {
		return false;
	}

	var arrParselist = parselist_request.parse_list;
	if (arrParselist) {//如果有数据
		for (var i = 0; i < arrParselist.length; i++) {
			for (var j = 0; j < formData.length; j++) {
				if (arrParselist[i].name == formData[j].value) {
					alert("请勿重复输入相同的协议解析表");
					return false;
				}
			}
		}
		var parseWeb = {
			"cfgType": "2",
			// "cfgName": "",
			"cfgName": "parse_list_cfg.json",
			"content": "",
			// "syncNodes": "",
		}

		var parseSave = {
			"cfg_type": 2,
			"datasz": "",
			"parse_list": ""
		}

		var parseA = {
			"name": "xxxx",
			"context": "xxxx"
		}

		var json = []
		var j = 1;
		parseA.name = formData[0].value;
		for (var i = 1; i < formData.length; i++) {
			var obj = {}
			if (formData[i].name == "list" + j) {
				parseA.context = json;
				arrParselist.push(parseA);
				json = []
				var parseA = {
					"name": "xxxx",
					"context": "xxxx"
				}
				parseA.name = formData[i].value;
				j++;
				i++;
			}
			formData[i].name = "name";
			formData[i + 1].name = "value_type";
			formData[i + 2].name = "value_length";
			obj[formData[i].name] = formData[i]['value'];
			obj[formData[i + 1].name] = formData[i + 1]['value'];
			obj[formData[i + 2].name] = parseInt(formData[i + 2]['value']);
			if (formData[i + 1]['value'] == "char") {
				obj[formData[i + 2].name] = 1;
			} else if (formData[i + 1]['value'] == "short") {
				obj[formData[i + 2].name] = 2;
			} else if (formData[i + 1]['value'] == "int") {
				obj[formData[i + 2].name] = 4;
			} else if (formData[i + 1]['value'] == "double") {
				obj[formData[i + 2].name] = 8;
			} else if (formData[i + 1]['value'] == "float") {
				obj[formData[i + 2].name] = 4;
			} else if (formData[i + 1]['value'] == "long") {
				obj[formData[i + 2].name] = 8;
			} else if (formData[i + 1]['value'] == "unsigned char") {
				obj[formData[i + 2].name] = 1;
			} else if (formData[i + 1]['value'] == "unsigned short") {
				obj[formData[i + 2].name] = 2;
			} else if (formData[i + 1]['value'] == "unsigned int") {
				obj[formData[i + 2].name] = 4;
			} else if (formData[i + 1]['value'] == "unsigned long") {
				obj[formData[i + 2].name] = 8;
			}
			// if (formData[i + 3].value != "") {
			// 	formData[i + 3].name = "logical_expressions";
			// 	obj[formData[i + 3].name] = formData[i + 3]['value'];
			// }
			formData[i + 3].name = "logical_expressions";
			obj[formData[i + 3].name] = formData[i + 3]['value'];
			formData[i + 4].name = "dbfield";
			obj[formData[i + 4].name] = formData[i + 4]['value'];
			formData[i + 5].name = "unit";
			obj[formData[i + 5].name] = formData[i + 5]['value'];
			json.push(obj);
			i = i + 5;
		}
		parseA.context = json;
		arrParselist.push(parseA);
		console.log(arrParselist);
		parseSave.parse_list = arrParselist;
		parseWeb.content = JSON.stringify(parseSave);
		console.log(parseWeb);
		postQuestSave(parseWeb);
		alert("新增成功！");
		//refreshTab();
		window.location.reload();
	} else {//如果没有数据
		arrParselist = [];

		var parseWeb = {
			"cfgType": "2",
			// "cfgName": "",
			"cfgName": "parse_list_cfg.json",
			"content": "",
			// "syncNodes": "",
		}

		var parseSave = {
			"cfg_type": 2,
			"datasz": "",
			"parse_list": ""
		}

		var parseA = {
			"name": "xxxx",
			"context": "xxxx"
		}

		var json = []
		var j = 1;
		parseA.name = formData[0].value;
		for (var i = 1; i < formData.length; i++) {
			var obj = {}
			if (formData[i].name == "list" + j) {
				parseA.context = json;
				arrParselist.push(parseA);
				json = []
				var parseA = {
					"name": "xxxx",
					"context": "xxxx"
				}
				parseA.name = formData[i].value;
				j++;
				i++;
			}
			formData[i].name = "name";
			formData[i + 1].name = "value_type";
			formData[i + 2].name = "value_length";
			obj[formData[i].name] = formData[i]['value'];
			obj[formData[i + 1].name] = formData[i + 1]['value'];
			obj[formData[i + 2].name] = parseInt(formData[i + 2]['value']);
			if (formData[i + 1]['value'] == "char") {
				obj[formData[i + 2].name] = 1;
			} else if (formData[i + 1]['value'] == "short") {
				obj[formData[i + 2].name] = 2;
			} else if (formData[i + 1]['value'] == "int") {
				obj[formData[i + 2].name] = 4;
			} else if (formData[i + 1]['value'] == "double") {
				obj[formData[i + 2].name] = 8;
			} else if (formData[i + 1]['value'] == "float") {
				obj[formData[i + 2].name] = 4;
			} else if (formData[i + 1]['value'] == "long") {
				obj[formData[i + 2].name] = 8;
			} else if (formData[i + 1]['value'] == "unsigned char") {
				obj[formData[i + 2].name] = 1;
			} else if (formData[i + 1]['value'] == "unsigned short") {
				obj[formData[i + 2].name] = 2;
			} else if (formData[i + 1]['value'] == "unsigned int") {
				obj[formData[i + 2].name] = 4;
			} else if (formData[i + 1]['value'] == "unsigned long") {
				obj[formData[i + 2].name] = 8;
			}
			// if (formData[i + 3].value != "") {
			// 	formData[i + 3].name = "logical_expressions";
			// 	obj[formData[i + 3].name] = formData[i + 3]['value'];
			// }
			formData[i + 3].name = "logical_expressions";
			obj[formData[i + 3].name] = formData[i + 3]['value'];
			formData[i + 4].name = "dbfield";
			obj[formData[i + 4].name] = formData[i + 4]['value'];
			formData[i + 5].name = "unit";
			obj[formData[i + 5].name] = formData[i + 5]['value'];
			json.push(obj);
			i = i + 5;
		}
		parseA.context = json;
		arrParselist.push(parseA);
		console.log(arrParselist);
		parseSave.parse_list = arrParselist;
		parseWeb.content = JSON.stringify(parseSave);
		console.log(parseWeb);
		postQuestSave(parseWeb);
		alert("新增成功！");
		//refreshTab();
		window.location.reload();
	}

}


//删除协议字段解析表JSON
function parselist_modify(args) {
	var arrParselist = []
	var parseWeb = {
		"cfgType": 2,
		"deletedName": ""
	}
	parseWeb.deletedName = args;
	arrParselist.push(parseWeb)
	sss = JSON.stringify(arrParselist)
	$.ajax({
		url: 'http://' + ipm + ':8081/dict/deleteProto',
		type: 'POST',
		contentType: 'application/json',
		dataType: 'json',
		data: sss,
		success: function (response) {
			console.log(response);
		}
	});
	window.location.reload();
}



//更新编辑解析表JSON
function buildEditParselistJson() {
	var register = $("#parselistForm1");
	var formData = register.serializeArray();
	console.log(formData);
	var arrParselist = parselist_request.parse_list;
	console.log(arrParselist);
	var parseWeb = {
		"cfgType": "2",
		"cfgName": "parse_list_cfg.json",
		"content": "",
		// "syncNodes": "",
	}
	var parseSave = {
		"cfg_type": 2,
		"datasz": "",
		"parse_list": ""
	}
	var json = []
	var arr = []
	var total_length = 0
	console.log(parselistnameroom);
	for (var i = 0; i < arrParselist.length; i++) {
		if (arrParselist[i].name == parselistnameroom) {
			for (var j = 0; j < formData.length; j++) {
				var obj = {}
				formData[j].name = "name";
				formData[j + 1].name = "value_type";
				formData[j + 2].name = "value_length";
				obj[formData[j].name] = formData[j]['value'];
				obj[formData[j + 1].name] = formData[j + 1]['value'];
				obj[formData[j + 2].name] = parseInt(formData[j + 2]['value']);
				if (formData[j + 1]['value'] == "char") {
					//obj[formData[j + 2].name] = 1;
				} else if (formData[j + 1]['value'] == "short") {
					obj[formData[j + 2].name] = 2;
				} else if (formData[j + 1]['value'] == "int") {
					obj[formData[j + 2].name] = 4;
				} else if (formData[j + 1]['value'] == "double") {
					obj[formData[j + 2].name] = 8;
				} else if (formData[j + 1]['value'] == "float") {
					obj[formData[j + 2].name] = 4;
				} else if (formData[j + 1]['value'] == "long") {
					obj[formData[j + 2].name] = 8;
				} else if (formData[j + 1]['value'] == "unsigned char") {
					//obj[formData[j + 2].name] = 1;
				} else if (formData[j + 1]['value'] == "unsigned short") {
					obj[formData[j + 2].name] = 2;
				} else if (formData[j + 1]['value'] == "unsigned int") {
					obj[formData[j + 2].name] = 4;
				} else if (formData[j + 1]['value'] == "unsigned long") {
					obj[formData[j + 2].name] = 8;
				}
				total_length += obj[formData[j + 2].name]
				formData[j + 3].name = "logical_expressions";
				obj[formData[j + 3].name] = formData[j + 3]['value'];
				console.log(formData)
				formData[j + 4].name = "dbfield";
				obj[formData[j + 4].name] = formData[j + 4]['value'];
				formData[j + 5].name = "unit";
				obj[formData[j + 5].name] = formData[j + 5]['value'];
				json.push(obj);
				j = j + 5;
			}
			console.log(json);
			arrParselist[i].context = json;
			arr.push(arrParselist[i]);
		} else {
			arr.push(arrParselist[i]);
		}
	}

	console.log(total_length);
	parseSave.parse_list = arr;
	console.log(arr)

	parseWeb.content = JSON.stringify(parseSave)
	console.log(parseSave)
	postQuestSave(parseWeb);
	alert("修改成功！");
	//refreshTab();
	window.location.reload();
}
